﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using Microsoft.TeamFoundation.WorkItemTracking.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Controls;

namespace nxMgr
{
    interface IProcessDoubleClick
    {
        void ProcessItem(object item);
    }
    public partial class FormWorkItem : Form, IProcessDoubleClick 
    {
        private bool m_IsNewWI;
        private WorkItemFormControl wifCtl = null; 

        public FormWorkItem(WorkItem wi)
        {
            InitializeComponent();
            SetupWorkItemControl(wi);
        }


        private void SetupWorkItemControl(WorkItem wi)
        {
            if (wi.Id == 0)
            {
                m_IsNewWI = true;
                this.Text = "New " + wi.Type.Name;
            }
            else
            {
                this.Text = "Details for Work Item " + wi.Id.ToString();
            }

            if (wifCtl == null)
            {
                wifCtl = new WorkItemFormControl();
                wifCtl.Dock = DockStyle.Fill;
                wifCtl.BackColor = System.Drawing.SystemColors.Window;
                wifCtl.ReadOnly = false;
                this.SetClientSizeCore(wifCtl.ClientRectangle.Width, wifCtl.ClientRectangle.Height + this.pnlButtons.ClientRectangle.Height);
                this.pnlWICtl.Controls.Add(wifCtl);
            }
            wifCtl.Item = wi;
        }

        public void ProcessItem(object item)
        {
            if (item is WorkItem)
            {
                this.SetupWorkItemControl((WorkItem)item);
            }
        }

    }
}
